package com.hst.capacity.domain.service.impl;

import com.hst.capacity.domain.model.request.statistics.StatisticsParam;
import com.hst.capacity.domain.model.response.PagingResultVO;
import com.hst.capacity.domain.model.response.statistics.StatisticsDailyVO;
import com.hst.capacity.domain.service.StatisticsService;
import com.hst.capacity.infra.persistence.jpa.statistics.StatisticsDailyRepository;
import com.hst.capacity.infra.persistence.mybatis.StatisticsMapper;
import com.hst.capacity.infra.util.DateUtil;
import com.hst.capacity.infra.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    StatisticsDailyRepository statisticsDailyRepository;

    @Autowired
    StatisticsMapper statisticsMapper;

    @Override
    public PagingResultVO<StatisticsDailyVO> findStatisticsDailyLst(StatisticsParam param) {
        try {
            if (StringUtil.isNotBlank(param.getCreatTimeE()) && StringUtil.isNotBlank(param.getCreatTimeF())) {
                param.setCountDayE(Integer.parseInt(param.getCreatTimeE().replace("-", "")));
                param.setCountDayF(Integer.parseInt(param.getCreatTimeF().replace("-", "")));
            }
        } catch (Exception e) {
            log.info("统计时间转换出错");
        }
        return new PagingResultVO<>(statisticsMapper.searchWithConditionsAndPagingTotal(param), statisticsMapper.searchWithConditionsAndPaging(param));
    }

    @Override
    public StatisticsDailyVO getStatisticsDataOne(StatisticsParam param) {
        return statisticsMapper.getStatisticsDataOne(param);
    }

}
